﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.guide.actions {
    import flash.events.*;
    import flash.geom.*;
    import Modules.guide.ui.*;
    import Engine.*;

    public class GADisplayArrow extends GADisplayTarget {

        private const TARGET_ARROW:String = "arrow";

        protected var m_arrowURL:String = "";
        protected var m_direction:int = 4;
        protected var m_useRotate:Boolean = true;
        protected var m_arrowWidth:Number = 0;
        protected var m_arrowHeight:Number = 0;
        protected var m_relativeTo:String = "";
        protected var m_offsetX:Number = 0;
        protected var m_offsetY:Number = 0;
        protected var m_arrow:GuideArrow = null;
        protected var m_aboveHud:Boolean = false;

        public function GADisplayArrow(){
            m_targetType = this.TARGET_ARROW;
            m_showOutline = false;
            super();
        }
        override public function createFromXml(_arg1:XML):Boolean{
            var _local2:Boolean = super.createFromXml(_arg1);
            var _local3:String = m_xml.@name;
            var _local4:String = m_xml.@arrowWidth;
            var _local5:String = m_xml.@arrowWidth;
            var _local6:String = m_xml.@direction;
            var _local7:String = m_xml.@rotate;
            var _local8:String = m_xml.@relative;
            var _local9:String = m_xml.@offsetX;
            var _local10:String = m_xml.@offsetY;
            var _local11:String = m_xml.@aboveHud;
            if (_local3.length == 0){
                return (false);
            };
            this.m_arrowURL = Global.getAssetURL(_local3);
            if (_local4.length > 0){
                this.m_arrowWidth = Number(_local4);
            };
            if (_local5.length > 0){
                this.m_arrowHeight = Number(_local5);
            };
            if (_local9.length > 0){
                this.m_offsetX = Number(_local9);
            };
            if (_local10.length > 0){
                this.m_offsetY = Number(_local10);
            };
            if (_local6.length > 0){
                _local6 = _local6.toLowerCase();
                switch (_local6){
                    case "up":
                        this.m_direction = GuideArrow.ARROW_UP;
                        break;
                    case "down":
                        this.m_direction = GuideArrow.ARROW_DOWN;
                        break;
                    case "right":
                        this.m_direction = GuideArrow.ARROW_RIGHT;
                        break;
                    case "left":
                    default:
                        this.m_direction = GuideArrow.ARROW_LEFT;
                };
            };
            this.m_aboveHud = (((_local11.length > 0)) && ((_local11.toLowerCase() == "true")));
            if ((((_local7.length > 0)) && ((_local7.toLowerCase() == "false")))){
                this.m_useRotate = false;
            } else {
                this.m_useRotate = true;
            };
            if (_local8.length > 0){
            };
            return (_local2);
        }
        override public function enter():void{
            var _local1:Point;
            var _local2:Point;
            var _local3:Point;
            super.enter();
            if (!m_focus){
                return;
            };
            _local1 = new Point(m_focus.x, m_focus.y);
            switch (m_mode){
                case GADisplayTarget.MODE_RELATIVE:
                    _local2 = m_target.localToGlobal(new Point(_local1.x, _local1.y));
                    _local2 = Global.ui.globalToLocal(_local2);
                    _local1.x = (_local2.x + this.m_offsetX);
                    _local1.y = (_local2.y + this.m_offsetY);
                    break;
                case GADisplayTarget.MODE_TILE:
                    _local3 = IsoMath.tilePosToPixelPos(_local1.x, _local1.y);
                    _local3 = IsoMath.viewportToStage(_local3);
                    _local3 = Global.ui.globalToLocal(_local3);
                    _local1.x = (_local3.x + this.m_offsetX);
                    _local1.y = (_local3.y + this.m_offsetY);
                    break;
                case GADisplayTarget.MODE_TARGET_CLASS:
                    _local1 = Global.ui.globalToLocal(_local1);
                    _local1.x = (_local1.x + this.m_offsetX);
                    _local1.y = (_local1.y + this.m_offsetY);
                    break;
                case GADisplayTarget.MODE_LOCATION:
                case GADisplayTarget.MODE_TARGET_TYPE:
                case GADisplayTarget.MODE_ACTIVE_ROLL_CALL_TYPE:
                case GADisplayTarget.MODE_HUD:
                case GADisplayTarget.MODE_PEDDLERBAR:
                    _local1.x = (_local1.x + this.m_offsetX);
                    _local1.y = (_local1.y + this.m_offsetY);
                    break;
            };
            this.m_arrow = new GuideArrow(this.m_arrowURL, _local1.x, _local1.y, this.m_arrowWidth, this.m_arrowHeight, this.m_direction, this.m_useRotate, this.m_aboveHud);
            m_guide.trackArrow(this.m_arrow);
            Global.stage.addEventListener(FullScreenEvent.FULL_SCREEN, this.onFullScreenChange);
        }
        private function onFullScreenChange(_arg1:Event):void{
            if ((((((this.m_arrow == null)) || ((this.m_arrow.getAsset() == null)))) || (!(m_focus)))){
                return;
            };
            var _local2:Array = m_guide.getArrows();
            if ((((_local2 == null)) || ((_local2.length == 0)))){
                return;
            };
            var _local3:int;
            while (_local3 < _local2.length) {
                if (_local2[_local3] == this.m_arrow){
                    Global.guide.removeMask();
                    Global.guide.removeArrows();
                    Global.stage.removeEventListener(FullScreenEvent.FULL_SCREEN, this.onFullScreenChange);
                    break;
                };
                _local3++;
            };
        }
        override protected function allAssetsLoaded():Boolean{
            if (!this.m_arrow){
                return (true);
            };
            return (this.m_arrow.hasLoaded());
        }

    }
}//package Modules.guide.actions 
